package com.dek.seckill.controller;

import com.dek.seckill.common.redis.RedisService;
import com.dek.seckill.common.redis.UserKey;
import com.dek.seckill.common.util.CodeMsg;
import com.dek.seckill.common.util.Result;
import com.dek.seckill.common.util.UUIDUtil;
import com.dek.seckill.entity.User;
import com.dek.seckill.service.UserService;
import com.dek.seckill.vo.LoginVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.validation.Valid;


@Controller
public class LoginController {

    @Autowired
    private UserService userService;

    @Autowired
    private RedisService redisService;

    @RequestMapping("login")
    public String login() {
        return "login";
    }

    @RequestMapping("doLogin")
    @ResponseBody
    public Result doLogin(@Valid LoginVO loginVO) {
        String mobile = loginVO.getMobile();
        CodeMsg codeMsg = userService.login(loginVO);
        return Result.error(codeMsg);
    }

    @RequestMapping("user")
    @ResponseBody
    public Result user() {
        User user = userService.getById(1);
        return Result.success(user);
    }

}
